/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can.generalisator;

import java.util.Random;

/**
 *
 * @author Thomas
 */
public class GenWorkingClass implements Generalisator{            
    private String[] government = {"Federal-gov", "State-gov", "Local-gov"};
    private String[] unemployed = {"Without-pay", "Never-worked"};
    private String[] privsector = {"Private", "Self-emp-not-inc", "Self-emp-inc"};

    @Override
    public String gen(String value) {
        for(String target : privsector){
            if(value.contains(target))
                return "Priv. Sector";
        }
        for(String target : government){
            if(value.contains(target))
                return "Government";
        }
        for(String target : unemployed){
            if(value.contains(target))
                return "Unemployed";
        }
        return "*";    
    }

    @Override
    public int getMaxGeneralisation() {
        return 3;
    }

    @Override
    public double getLength(String value) {
        if(value.equals("*"))
            return 3.0;
        for(String target : privsector){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : government){
            if(value.contains(target))
                return 1.0;
        }
        for(String target : unemployed){
            if(value.contains(target))
                return 1.0;
        }
        return 2.0;
    }

    @Override
    public double getMaxLength() {
        return 4.0;
    }

    @Override
    public String getUngeneralisation(String value) {
        Random rand = new Random(System.nanoTime());
        if(value.equals("*"))
            return "Government";
        if(value.equals("Priv. Sector"))
           return privsector[rand.nextInt(privsector.length)];
        else if(value.equals("Government"))
           return government[rand.nextInt(government.length)];
        else
            return unemployed[rand.nextInt(unemployed.length)];
    }

    @Override
    public int getGeneralisationLevel(String value) {
        if(value.equals("*"))
            return 2;
        for(String target : privsector){
            if(value.contains(target))
                return 0;
        }
        for(String target : government){
            if(value.contains(target))
                return 0;
        }
        for(String target : unemployed){
            if(value.contains(target))
                return 0;
        }
        return 1;
    }
    
}
